{extend name="base/main" /}
{block name="body"}
<form class="layui-form" action="{:url('navigation/update')}" method="post">
  <div class="layui-form-item">
    <label class="layui-form-label">导航名称</label>
    <div class="layui-input-inline">
      <input type="text" name="dname" required  value="{$data.dname}" lay-verify="required" placeholder="请输入导航名称" autocomplete="off" class="layui-input">
    </div>
  </div>

 <div class="layui-form-item">
    <label class="layui-form-label">排序</label>
    <div class="layui-input-inline">
      <input type="text" name="age" required value="{$data.age}" lay-verify="required" placeholder="请输入排序" autocomplete="off" class="layui-input">
    </div>
  </div>
 
<div class="layui-form-item">
    <label class="layui-form-label">一级分类</label>
    <div class="layui-input-inline">
      <input type="text" name="yname" required value="{$data.yname}" lay-verify="required" placeholder="请输入一级分类" autocomplete="off" class="layui-input">
    </div>
  </div>

<div class="layui-upload">
    <label class="layui-form-label" style="width: 80px">图标</label>
  <button type="button" class="layui-btn" id="test1">图标</button>
  <div class="layui-upload-list">
    <img class="layui-upload-img" style="margin-left: 110px" id="demo1" name="img" width="100px" height="100px" src="{$data.img}">
    <p id="demoText"></p>
    <input type="hidden" name="img" value="{$data.img}" id="img">
  </div>
</div>   

  <div class="layui-form-item">
    <div class="layui-input-block">
    <input type="hidden" name="id" value="{$data.id}">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script>
//Demo
layui.use(['upload', 'element', 'layer','form'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,element = layui.element
            ,layer = layui.layer;
        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: "{:url('Navigation/upload')}" //改成自己的上传接口
            ,before: function(obj){
                //预读本地文件示例
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                if(res.code == 0){
                    $('#img').val(res.data);
                    return layer.msg('上传成功');
                }
                //上传成功的一些操作
                //……
                $('#demoText').html(''); //置空上传失败的状态
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
 });
</script>
{/block}